import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';

// pages/report/report.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    CId:"",
    //下拉框类型
    option1: [{
        "text": 'elevator',
        "value": 0
      },
      {
        "text": 'computer',
        "value": 1
      },
      {
        "text": 'printer',
        "value": 2
      },
      {
        "text": 'air',
        "value": 3
      },
      {
        "text": 'light',
        "value": 4
      },
      {
        "text": 'others',
        "value": 5
      },
    ],
    value1: 0,

    // 报修的设备类型
    dev_type:"",

    //详细描述
    message: "",


    // 报修信息
    CPhone: "",
    CAddress: "",
    // "dev_describ": "",

    // 底部tabbar start
    tabbar_active: 0,
    tabbar_list: [{
      "url": "../report/report",
      "text": "报修",
      "icon": "comment-circle"
    }, {
      "url": "../urge/urge",
      "text": "催单",
      "icon": "clock",
      //"info": "3"
    }, {
      "url": "../myinfo/myinfo",
      "text": "我的",
      "icon": "smile",
    }, {
      "url": "../contact1/contact1",
      "text": "关于",
      "icon": "phone-circle",
    }]

  },

  submit() {
    console.log('submit success 获取信息请直接使用 类型：dev_type 描述：message');
    wx.request({
      url: 'http://localhost:8088/appNewTask',
      method:'GET',
      data:{
        CId:this.data.CId,
        skill:this.data.dev_type,
        description:this.data.message
      },
      success(res){
        var data1 = res.data;
        if("SUCCESS" == data1){
          Toast('报修信息提交成功~');
        }
      }
    });
    
  },

  onSwitchChange(e) {
    this.setData({
      dev_type: this.data.option1[e.detail].text
    });
    // console.log(e);
    console.log('类型：' + this.data.option1[e.detail].text);
    // console.log(this.data.option1[e.detail].text);
  },

  details(event) {
    this.setData({
      message: event.detail
    });
    console.log("描述：" + event.detail)
  },

  tabbar_onChange: function (res) {
    this.setData({
      tabbar_active: res.detail
    });
    // console.log(this.data.tabbar_list[res.detail].url);
    wx.navigateTo({
      url: this.data.tabbar_list[res.detail].url+"?Id="+this.data.CId,
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      CId:options.Id,
    })
    const that = this;
    wx.request({
      url: 'http://localhost:8088/getMyClient',
      method:'GET',
      data:{
        CId:this.data.CId,
      },
      success(res){
        var data1 = res.data;
        that.setData({
          CAddress:data1.cAddress,
          CPhone:data1.cPhone,
        });
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})